//
//  ByServiceGoodServiceDetailVC.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/11/10.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByServiceGoodServiceDetailVC.h"

// view
#import "ByViewProductDetailToolBar.h"                  // 工具栏
#import "ByViewProductDetailCommentHeader.h"            // 评论头视图
#import "ByViewSkuSelect.h"                             // 规格选择

// cell
#import "ByCellServiceGoodDetailInfo.h"                 // 信息
#import "ByCellServiceGoodDetailNote.h"
#import "ByCellServiceGoodDetailService.h"              // 服务
#import "ByCellServiceGoodListItem.h"                   // 列表元素

@interface ByServiceGoodServiceDetailVC () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) UIImageView *header;
@property (nonatomic, strong) ByViewProductDetailToolBar *toolBar;

@end

@implementation ByServiceGoodServiceDetailVC
{
    
}

#pragma mark - view method
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"营销活动详情";
    
    [self addLeftBackBarButtonItem];
    
    [self createViews];
}

#pragma mark - 请求数据

#pragma mark - 创建视图
- (void)createViews {
        
    // 工具栏
    _toolBar = [[ByViewProductDetailToolBar alloc] initWithFrame:CGRectZero mainTitles:@[@"加入购物车", @"立即购买"] mainFgColors:@[[UIColor whiteColor], BY_GOLD_COLOR] mainBgColors:@[BY_GOLD_COLOR, BY_THEME_COLOR] mainRatio:0.5 subTitles:@[@"收藏", @"客服", @"分享"] subImages:@[@"", @"", @""]];
    [self.view addSubview:_toolBar];
    _toolBar.functionClickBlock = ^(NSInteger index, BOOL selected) {
        if (index == 3 || index == 4) {
            
        }
    };
    [_toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.height.equalTo(@49);
        if (@available(ios 11.0,*)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
        } else {
            make.bottom.equalTo(@0);
        }
    }];
    
    // 标示图
    self.table = [[UITableView alloc] init];
    self.table.backgroundColor = BY_BG_COLOR;
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(_toolBar);
        make.top.equalTo(@0);
        make.bottom.equalTo(_toolBar.mas_top);
    }];
    self.table.tableHeaderView = self.header;
    
    // 注册
    [self.table registerClass:[ByCellServiceGoodDetailInfo class] forCellReuseIdentifier:@"infoCell"];
    [self.table registerClass:[ByCellServiceGoodDetailService class] forCellReuseIdentifier:@"serviceCell"];
    [self.table registerClass:[ByCellServiceGoodListItem class] forCellReuseIdentifier:@"hotCell"];
    [self.table registerClass:[ByCellServiceGoodDetailNote class] forCellReuseIdentifier:@"noteCell"];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    /*
     0：商品描述
     1：不要宅了。。。。
     2：服务描述
     3：活动详情
     4：热门推荐
     */
    return 5;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 2) {
        return 2;
    }
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // 0：商品描述
    if (indexPath.section == 0) {
        ByCellServiceGoodDetailInfo *cell = [tableView dequeueReusableCellWithIdentifier:@"infoCell"];
        return cell;
    }
    // 1：不要宅了。。。。
    else if (indexPath.section == 1) {
        ByCellServiceGoodDetailNote *cell = [tableView dequeueReusableCellWithIdentifier:@"noteCell"];
        return cell;
    }
    // 2：服务描述
    else if (indexPath.section == 2) {
        ByCellServiceGoodDetailService *cell = [tableView dequeueReusableCellWithIdentifier:@"serviceCell"];
        return cell;
    }
    // 3：活动详情
    else if (indexPath.section == 3) {

    }
    // 4：热门推荐
    else if (indexPath.section == 4) {
        ByCellServiceGoodListItem *cell = [tableView dequeueReusableCellWithIdentifier:@"hotCell"];
        return cell;
    }
 
    
    return [UITableViewCell new];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    // 0：
    if (indexPath.section == 0) {
        return [tableView fd_heightForCellWithIdentifier:@"infoCell" cacheByIndexPath:indexPath configuration:^(ByCellServiceGoodDetailInfo *cell) {
            
        }];
    }
    // 1：
    else if (indexPath.section == 1) {
        return 44;
    }
    // 2：
    else if (indexPath.section == 2) {
        return 100 + 10;
    }
    // 3：
    else if (indexPath.section == 3) {
        return 100;
    }
    // 4：热门
    else if (indexPath.section == 4) {
        return (SCREEN_WIDTH - 20) / 2 + 50 + 36 + 10;
    }
    
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    if (section == 4 || section == 3) {
        return 40;
    }
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    if (section == 3 || section == 4) {
        UIView *header = [UIView new];
        
        // 线条
        UIView *line = [UIView new];
        line.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
        [header addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(header).multipliedBy(0.5);
            make.centerX.equalTo(@0);
            make.centerY.equalTo(@0);
            make.height.equalTo(@1);
        }];
        
        UILabel *label = [[UILabel alloc] init];
        label.backgroundColor = tableView.backgroundColor;
        label.font = FONT(14);
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = [UIColor lightGrayColor];
        [header addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@80);
            make.top.bottom.equalTo(@0);
            make.centerX.equalTo(@0);
        }];
        
        if (section == 3) {
            label.text = @"活动详情";
        } else {
            label.text = @"热门推荐";
        }
        
        return header;
    }
    return UIView.new;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return UIView.new;
}


#pragma mark - getter
- (UIImageView *)header {
    
    if (!_header) {
        _header = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, self.view.width / 2)];
        _header.image = [UIImage imageNamed:@"头视图背景"];
    }
    return _header;
}

@end
